<?php get_header(); ?>
<article id="mainContain" class="wrapper">
  <section class="floatLeft" id="lastestPost">
  <?php
    global $query_string;
    $query_args = explode("&", $query_string);
    $search_query = array();
    foreach($query_args as $key => $string) {
      $query_split = explode("=", $string);
      $search_query[$query_split[0]] = urldecode($query_split[1]);
    }
    $search_query['post_type'] = 'post';
    $search = new WP_Query($search_query); ?>
    <?php if ($search->have_posts()) : while ($search->have_posts()) : $search->the_post(); ?>
    <?php $categories = get_the_category(get_the_ID()); ?>
    <?php $comments = get_comments_number(get_the_ID()) > 1 ? get_comments_number(get_the_ID())." comments" : get_comments_number(get_the_ID())." comment"; ?>
      <div id="newItem-<?php echo get_the_ID(); ?>" class="lastItems">
        <div class="postImg floatLeft">
          <a href="<?php the_permalink(); ?>">
            <?php if(has_post_thumbnail(get_the_ID())) : ?>
              <?php $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full'); ?>
              <img src="<?php echo CORE_TIMTHUMB_URL.$thumb."&w=215";?>" alt="<?php the_title(); ?>">
          <?php else : ?>
            <?php $thumbMeta = get_post_meta(get_the_ID(), 'thumbnail', true); ?>
            <?php if(!empty($thumbMeta)) : ?>
              <img src="<?php echo CORE_TIMTHUMB_URL.get_post_meta(get_the_ID(), 'thumbnail', true)."&w=215";?>" alt="<?php the_title(); ?>">
            <?php else : ?>
            <img src="<?php echo CORE_TIMTHUMB_URL.CORE_THEME_IMAGE."no-image.jpg&w=215&h=150";?>" alt="<?php the_title(); ?>">
            <?php endif; ?>
          <?php endif; ?>
          </a>
          <div class="tag">
            <?php foreach($categories as $category) : ?>
              <a href="<?php echo get_category_link($category->term_id); ?>">#<?php echo $category->name; ?></a>
            <?php endforeach; ?>
          </div>
          <!-- /.tag -->
        </div>
        <!-- /.postImg -->
        <div class="postDescription floatRight">
          <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
          <ul>
            <li class="author"><a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php the_author(); ?></a></li>
            <li class="time"><?php the_date('d/m/Y'); ?></li>
            <li class="comments"><a href="<?php the_permalink(); ?>#disqus_thread"><?php echo $comments; ?></a></li>
          </ul>
          <p><?php the_excerpt(); ?></p>
        </div>
        <!-- /.postDescription -->
        <div class="clearfix"></div>
      </div>
      <!-- /.lastItems -->

    <?php endwhile; endif; ?>
    <?php wp_reset_postdata(); ?>
    <?php wp_pagenavi(); ?>

  </section>

  <!-- /#lastestPost.floatLeft -->

  <?php get_sidebar(); ?>

  <div class="clearfix"></div>
</article>

<!-- /#mainContent.wrapper -->
<?php get_footer(); ?>